﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using ECommerce.Library.DataStructure;
using AutoGear.BLL;
using ECommerce.Library;
using System.Web.UI;
using eShop.Model;
using eShop.Business;


/// <summary>
/// Summary description for Search
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class Search : System.Web.Services.WebService {

    [WebMethod]
    public string[] GetProductsByTerm(string prefixText, int count)
    {
        List<string> result = new List<string>();
        ReadWriteCustomCollection<Product> products = Product.Search(prefixText, "", SearchType.SearchByItemNumberAndKeyword);

        foreach (Product p in products)
            result.Add(p.ProductName);

        return result.ToArray();
    }


    [WebMethod]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public List<Category> GetProductCategories(string orderBy)
    {
        List<Category> result = new List<Category>();

        CategoryManager.GetBackendCategoryList(true, "", 0, 10);

        return result;
    }

    [WebMethod]
    public string[] GetProductTitlesWithImages(string prefixText, int count)
    {
        ReadWriteCustomCollection<Product> list = Product.Search(prefixText, prefixText, SearchType.SearchByItemNumberAndKeyword);
        List<string> gameList = new List<string>();
        for (int i = 0; i < list.Count; i++)
       {
            //int len = prefixText.Length;
            //if (prefixText.ToUpper() == list[i].ProductName.Substring(0, len).ToUpper())
            //    gameList.Add(list[i].ProductName + "," + SiteGlobals.BaseUrl+list[i].ProductImageSmallThumbnail.Replace("~/",""));
            //else
            //    gameList.Add(list[i].ProductName2 + "," + SiteGlobals.BaseUrl + list[i].ProductImageSmallThumbnail.Replace("~/", ""));
           gameList.Add(list[i].ProductName + "," + list[i].ProductImageSmallThumbnail.Replace("~/", SiteGlobals.BaseUrl));
            
         }
        return gameList.ToArray();
    }
}
